using System;

namespace SharpMud.MudLib.Core.Scripting
{
	public class ScriptManager
	{
		public ScriptManager()
		{
		}
	}

	public class CombinationScriptSegment : ScriptSegment
	{
		private ScriptSegment[] _Segments;
		public ScriptSegment[] Segments
		{
			get
			{
				return _Segments;
			}
		}

		public override string ActiveSegmentContent
		{
			get
			{
				return base.ActiveSegmentContent;
			}
		}

		public override string InactiveSegmentContent
		{
			get
			{
				return base.InactiveSegmentContent;
			}
			set
			{
				throw new InvalidOperationException("You cannot set the InactiveSegmentContent on a CombinationScriptSegment.");
			}
		}


		public CombinationScriptSegment(System.Guid guid, ScriptSegment[] segments)
			:base(guid)
		{
			this._Segments = segments;
		}
	}

	public class ScriptSegment
	{
		private System.Guid _SegmentGuid;
		public System.Guid SegmentGuid
		{
			get
			{
				return _SegmentGuid;
			}
			set
			{
				_SegmentGuid = value;
			}
		}

		private string _ActiveContent;
		private string _InactiveContent;

		public virtual string InactiveSegmentContent
		{
			get
			{
				return _InactiveContent;
			}
			set
			{
				if(_ActiveContent==value && _InactiveContent!=value)
				{
					//The content has changed back to something it was since it
					//was "dirtied"
					_InactiveContent = value;
					if(ContentCleaned!=null) ContentCleaned(this,null);
				}
				else if(_ActiveContent!=value && _InactiveContent==_ActiveContent)
				{
					//The content has changed since it was last made active
					_InactiveContent = value;
					if(ContentDirtied!=null) ContentDirtied(this,null);
				}
				else
				{
					_InactiveContent = value;
				}
			}
		}

		public event System.EventHandler ContentDirtied;
		public event System.EventHandler ContentCleaned;

		public virtual string ActiveSegmentContent
		{
			get
			{
				return _ActiveContent;
			}
		}

		public bool ContentIsDirty
		{
			get
			{
				return (_InactiveContent!=_ActiveContent);
			}
		}

		public void IncorporateContentChange()
		{
			if(ContentIsDirty)
			{
				_ActiveContent = _InactiveContent;
				if(ContentCleaned!=null) ContentCleaned(this,null);
			}
		}

		protected ScriptSegment(System.Guid segmentGuid)
		{
			this._SegmentGuid = segmentGuid;
		}

		public ScriptSegment(System.Guid segmentGuid, string content)
		{
			this._SegmentGuid = segmentGuid;
			this.InactiveSegmentContent = content;
		}
	}

	public class TypeDefinitionScriptSegment : ScriptSegment
	{
		public TypeDefinitionScriptSegment(System.Guid guid, string content)
			:base(guid,content)
		{
		
		}
	}

	public class ScriptedAssemblyConstruction : CombinationScriptSegment
	{
		public ScriptSegment ScriptSegments;

		public ScriptedAssemblyConstruction(System.Guid guid, ScriptSegment[] scriptSegments)
			:base(guid,scriptSegments)
		{
		}
	}
}